package com.trans.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Author xwduo
 * @Date 2023-09-07 16:28
 */
public class MapUtils {

    public static <T,U> void putIfExist(Map<T, List<U>> mapper, T key , U val){
        if( ! mapper.containsKey(key) ){
            mapper.put(key,new ArrayList<>());
        }
        mapper.get(key).add(val);
    }

    public static <T,U> void combine(Map<T, List<U>> origin,Map<T, List<U>> tar){
        if(null != tar && null != origin ){
            for (Map.Entry<T, List<U>> entry : tar.entrySet()) {
                if( ! origin.containsKey(entry.getKey()) ){
                    origin.put(entry.getKey(),new ArrayList<>());
                }
                origin.get(entry.getKey()).addAll(entry.getValue());
            }
        }
    }
}
